<template>
  <div class="home-nav">
    <div class="navs">
      <div class="nav">
        <div class="item" :class="getNavClass(nitem,nindex)" v-for="(nitem,nindex) in navList" :key="nindex" @click="navChange(nitem,nindex)">{{nitem.nav}}
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import {getMovieCategoryList} from '@/api/movieCategory'
export default {
  name: 'HomeNav',
  props: {
    navIndex: {}
  },
  data () {
    return {
      navList: []
    }
  },
  created () {
    this.fetchData()
  },
  methods: {
    getNavClass (item, index) {
      if (item.type == 1) {
        return 'orange'
      }
      if (item.type == 2) {
        return 'red'
      }
      if (this.navIndex == index) {
        return 'active'
      }
    },
    navChange (item, index) {
      this.navIndex = index
      if (this.navIndex == 0) {
        this.$router.push('/')
      } else {
        let routeUrl = this.$router.resolve({
          path: item.url,
          query: {id: item.id, index: parseInt(index)}
        })
        window.open(routeUrl.href, '_blank')
        // this.$router.push({path: item.url,query:{id:item.id,index:parseInt(index)}})
      }
    },
    fetchData () {
      getMovieCategoryList().then(response => {
        this.navList = response.data
      })
    }
  }
}
</script>

<style lang="scss" scoped>
  .home-nav {
    .navs {
      background: #191919;
      border-bottom: 2px solid #00A37C;
    }

    .nav {
      width: 980px;
      margin: auto;
      display: flex;
      align-items: center;

      .item {
        width: 90px;
        height: 50px;
        line-height: 50px;
        font-size: 14px;
        color: #fff;
        text-align: center;
        cursor: pointer;

        &:hover {
          background: #282828;
        }

        &.active {
          background: #00A37C;
        }
      }

      .orange {
        color: #FF9900;
      }

      .red {
        color: #FF3000;
      }
    }
  }
</style>
